import { BaseMsgHandler } from "../../framework/BaseMsgHandler";
import { DebugHost } from "../DebugHost";
import { ClientMsg } from "../../framework/common/ClientMsg";
import { DebugClient } from "../DebugClient";
import { EClientState } from "../../framework/common/EClientState";
import { EMessageC2S } from "../../../common/EMessageC2S";
import { EMessageS2C } from "../../../common/EMessageS2C";
import { WrapClientData } from "../../../common/CommonTransData";
import { EClientType } from "../../../common/EClientType";

export class HandleC1002 extends BaseMsgHandler<DebugHost> {

    msgId: number = EMessageC2S.QueryClientList;

    HandleMsg(msg: ClientMsg) {
        let client = msg.client as DebugClient;
        if (client.state != EClientState.Idle) {
            client.SendError('状态错误');
            return;
        }
        if (client.type != EClientType.Debugger) {
            client.SendError('类型错误');
            return;
        }
        let cacheClients: WrapClientData[] = [];
        for (let searchClient of this.owner.clientList) {
            if (searchClient.type == EClientType.Client) {
                let pushData = new WrapClientData();
                pushData.id = searchClient.id;
                pushData.name = searchClient.name;
                pushData.address = searchClient.remoteAddress;
                cacheClients.push(pushData);
            }
        }
        client.SendMsg(EMessageS2C.QueryClientList, cacheClients);
    }

}
